/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HauptFenster.java
 *
 * Created on 21.01.2010, 13:00:19
 */

package flugreservierung;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Rudi
 */
public class HauptFenster extends javax.swing.JFrame {

    private DataAccess da;
    private DefaultTableModel fluegeModel = new DefaultTableModel();
    /** Creates new form HauptFenster */
    public HauptFenster(DataAccess da) {
        this.da = da;
        initComponents();
        fillTable();
    }

    private void fillTable()
    {
       try
        {
            fluegeModel.addColumn("Flugnummer");
            fluegeModel.addColumn("von");
            fluegeModel.addColumn("nach");
            for (Flug f : da.findeFluege())
            {
                String[] reihe = new String[3];
                reihe[0] = String.valueOf(f.getNummer());
                reihe[1] = f.getVon();
                reihe[2] = f.getNach();
                fluegeModel.addRow(reihe);
            }

            flugTabelle.setModel(fluegeModel);
        } catch (FlugReservierungsException ex)
        {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        flugTabelle = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        flugTabelle.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(flugTabelle);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(157, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(78, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try
                {
                    new HauptFenster(new DBDataAccess()).setVisible(true);
                } catch (FlugReservierungsException ex)
                {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                    System.exit(-1);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable flugTabelle;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
